package com.application.meizhi.uitl.glideUtils;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.target.SizeReadyCallback;

/**
 * Created by Administrator on 2016/8/18 0018.
 */
public class GlideImgManager {

    public static final int CIRCLE = 1640;
    public static final int ROUND = 1641;

    /**
     * @param context
     * @param url
     * @param erroImg
     * @param emptyImg
     * @param iv
     */
    public static void glideLoader(Context context, String url, int erroImg, int emptyImg, ImageView iv, SizeReadyCallback callback) {
        //原生 API
        // Glide.with(context).load(url).placeholder(emptyImg).error(erroImg).into(iv);
        Glide.with(context)
                .load(url)
                .centerCrop()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(emptyImg)
                .error(erroImg)
                .into(iv)
                .getSize(callback);
    }

    public static void glideLoader(Context context, String url, int erroImg, int emptyImg, ImageView iv) {
        //原生 API
        Glide.with(context).load(url).diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(emptyImg).error(erroImg).into(iv);

    }

    /**
     * @param context
     * @param url
     * @param erroImg
     * @param emptyImg
     * @param iv
     * @param tag
     */
    public static void glideLoader(Context context, String url, int erroImg, int emptyImg, ImageView iv, int tag) {
        if (CIRCLE == tag) {
            Glide.with(context).load(url).placeholder(emptyImg).error(erroImg).diskCacheStrategy(DiskCacheStrategy.ALL).transform(new GlideCircleTransform(context)).into(iv);
        } else if (ROUND == tag) {
            Glide.with(context).load(url).placeholder(emptyImg).error(erroImg).diskCacheStrategy(DiskCacheStrategy.ALL).transform(new GlideRoundTransform(context, 10)).into(iv);
        }
    }
}
